<?php
class Language {
	
	var $language_id = "en";
	var $support_languages = array("en","ru");
	//English
	//Russian
	var $resource = null;
	
	var $instantsArray = array();
	var $showEmpty = true;
	
	public function __construct($lang_id=null) {
		if (isset($lang_id) && $this->isSupport($lang_id))
			$this->language_id = $lang_id;
	}
	
	function setResource(&$resource) {
		$this->resource = &$resource;
	}
	
	function msg($key) {
		if ($this->resource)
			return $this->resource->msg($key);
		if ($this->showEmpty) return "???";
		return "";
	}
	
	function isSupport($lang_id) {
		return in_array($lang_id, $this->support_languages);
	}
	
    function getId() {
    	return $this->language_id;
    }
    
    function &getInstant($lang_id) {
		if (isset($this->instantsArray[$lang_id])) return $this->instantsArray[$lang_id];
		$this->instantsArray[$lang_id] = new Language($lang_id);
		return $this->instantsArray[$lang_id];
	}
	
}
?>